package com.dao;

import java.util.ArrayList;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.springframework.stereotype.Controller;

import com.hibernate.pojo.Product;
import com.hibernate.pojo.Shopcar;

@Controller("shopCarDao")
public class ShopCarDao extends Basedao{

	
	public boolean add(Shopcar sc,Product p){
		try {
			getSession().save(sc);
			getSession().update(p);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}
	
	public ArrayList<Shopcar> getall(int userId){
		ArrayList<Shopcar> a = new ArrayList<Shopcar>();
		try {
			a = (ArrayList<Shopcar>)getSession().createQuery("from Shopcar sc where sc.userId=?").setInteger(0, userId).list();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return a;
	}
}
